################################################################################
## TITLE:		  figures_2spe_model
## DATA:      forecasts_1980_2020.dta
## AUTHORS:   Bruno J�r�me, V�ronique J�r�me, Philippe Mongrain, and Richard Nadeau
## PAPER:     State-Level Forecasts for the 2020 U.S. Presidential Election: Tough Victory Ahead for Biden
## DATE:		  August 2020


################################################################################
## INSTALL AND LOAD PACKAGES

# install.packages("dplyr")
# install.packages("ggplot2")
# install.packages("ggpubr")
# install.packages("gridExtra")
# install.packages("haven")
# install.packages("statebins")
# install.packages("usmap")

library(dplyr)
library(ggplot2)
library(ggpubr)
library(gridExtra)
library(haven)
library(statebins)
library(usmap)


################################################################################
## LOAD DATA

forecasts_1980_2020 <- read_dta("forecasts_1980_2020.dta")

View(forecasts_1980_2020)

forecasts_1980 <- forecasts_1980_2020 %>% filter(election == 1980)
forecasts_1984 <- forecasts_1980_2020 %>% filter(election == 1984)
forecasts_1988 <- forecasts_1980_2020 %>% filter(election == 1988)
forecasts_1992 <- forecasts_1980_2020 %>% filter(election == 1992)
forecasts_1996 <- forecasts_1980_2020 %>% filter(election == 1996)
forecasts_2000 <- forecasts_1980_2020 %>% filter(election == 2000)
forecasts_2004 <- forecasts_1980_2020 %>% filter(election == 2004)
forecasts_2008 <- forecasts_1980_2020 %>% filter(election == 2008)
forecasts_2012 <- forecasts_1980_2020 %>% filter(election == 2012)
forecasts_2016 <- forecasts_1980_2020 %>% filter(election == 2016)
forecasts_2020 <- forecasts_1980_2020 %>% filter(election == 2020)


################################################################################
## 1980 ELECTION

forecast.map.1980 <- plot_usmap(regions = "state", data = forecasts_1980, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.1980

outcome.map.1980 <- plot_usmap(regions = "state", data = forecasts_1980, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.1980

correct.map.1980 <- plot_usmap(regions = "state", data = forecasts_1980, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.1980

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.1980 <- grid.arrange(forecast.map.1980, outcome.map.1980, correct.map.1980, 
layout_matrix = layout_matrix); map.1980

dev.copy(pdf, "map_1980.pdf")
dev.off()


################################################################################
## 1984 ELECTION

forecast.map.1984 <- plot_usmap(regions = "state", data = forecasts_1984, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
              ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.1984

outcome.map.1984 <- plot_usmap(regions = "state", data = forecasts_1984, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
              ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.1984

correct.map.1984 <- plot_usmap(regions = "state", data = forecasts_1984, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.1984

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.1984 <- grid.arrange(forecast.map.1984, outcome.map.1984, correct.map.1984, 
layout_matrix = layout_matrix); map.1984

dev.copy(pdf, "map_1984.pdf")
dev.off()


################################################################################
## 1988 ELECTION

forecast.map.1988 <- plot_usmap(regions = "state", data = forecasts_1988, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
            ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.1988

outcome.map.1988 <- plot_usmap(regions = "state", data = forecasts_1988, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
            ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
forecast.map.1988

correct.map.1988 <- plot_usmap(regions = "state", data = forecasts_1988, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.1988

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.1988 <- grid.arrange(forecast.map.1988, outcome.map.1988, correct.map.1988, 
layout_matrix = layout_matrix); map.1988

dev.copy(pdf, "map_1988.pdf")
dev.off()


################################################################################
## 1992 ELECTION

forecast.map.1992 <- plot_usmap(regions = "state", data = forecasts_1992, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.1992

outcome.map.1992 <- plot_usmap(regions = "state", data = forecasts_1992, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.1992

correct.map.1992 <- plot_usmap(regions = "state", data = forecasts_1992, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.1992

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.1992 <- grid.arrange(forecast.map.1992, outcome.map.1992, correct.map.1992, 
layout_matrix = layout_matrix); map.1992

dev.copy(pdf, "map_1992.pdf")
dev.off()


################################################################################
## 1996 ELECTION

forecast.map.1996 <- plot_usmap(regions = "state", data = forecasts_1996, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                       ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.1996

outcome.map.1996 <- plot_usmap(regions = "state", data = forecasts_1996, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                        ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.1996

correct.map.1996 <- plot_usmap(regions = "state", data = forecasts_1996, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.1996

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.1996 <- grid.arrange(forecast.map.1996, outcome.map.1996, correct.map.1996, 
layout_matrix = layout_matrix); map.1996

dev.copy(pdf, "map_1996.pdf")
dev.off()


################################################################################
## 2000 ELECTION

forecast.map.2000 <- plot_usmap(regions = "state", data = forecasts_2000, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.2000

outcome.map.2000 <- plot_usmap(regions = "state", data = forecasts_2000, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                    ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.2000

correct.map.2000 <- plot_usmap(regions = "state", data = forecasts_2000, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.2000

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.2000 <- grid.arrange(forecast.map.2000, outcome.map.2000, correct.map.2000, 
layout_matrix = layout_matrix); map.2000

dev.copy(pdf, "map_2000.pdf")
dev.off()


################################################################################
## 2004 ELECTION

forecast.map.2004 <- plot_usmap(regions = "state", data = forecasts_2004, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                  ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.2004

outcome.map.2004 <- plot_usmap(regions = "state", data = forecasts_2004, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.2004

correct.map.2004 <- plot_usmap(regions = "state", data = forecasts_2004, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.2004

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.2004 <- grid.arrange(forecast.map.2004, outcome.map.2004, correct.map.2004, 
layout_matrix = layout_matrix); map.2004

dev.copy(pdf, "map_2004.pdf")
dev.off()


################################################################################
## 2008 ELECTION

forecast.map.2008 <- plot_usmap(regions = "state", data = forecasts_2008, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                  ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.2008

outcome.map.2008 <- plot_usmap(regions = "state", data = forecasts_2008, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.2008

correct.map.2008 <- plot_usmap(regions = "state", data = forecasts_2008, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.2008

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.2008 <- grid.arrange(forecast.map.2008, outcome.map.2008, correct.map.2008, 
layout_matrix = layout_matrix); map.2008

dev.copy(pdf, "map_2008.pdf")
dev.off()


################################################################################
## 2012 ELECTION

forecast.map.2012 <- plot_usmap(regions = "state", data = forecasts_2012, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                 ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.2012

outcome.map.2012 <- plot_usmap(regions = "state", data = forecasts_2012, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("#0C56BC", "red3")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.2012

correct.map.2012 <- plot_usmap(regions = "state", data = forecasts_2012, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.2012

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.2012 <- grid.arrange(forecast.map.2012, outcome.map.2012, correct.map.2012, 
layout_matrix = layout_matrix); map.2012

dev.copy(pdf, "map_2012.pdf")
dev.off()


################################################################################
## 2016 ELECTION

forecast.map.2016 <- plot_usmap(regions = "state", data = forecasts_2016, 
values = "fstatewinner_o", labels = FALSE) + scale_fill_manual(name = "
                  ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(a) Predicted winner in each state"); 
forecast.map.2016

outcome.map.2016 <- plot_usmap(regions = "state", data = forecasts_2016, 
values = "statewinner", labels = FALSE) + scale_fill_manual(name = "
                   ", values = c("red3", "#0C56BC")) + 
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(b) Actual winner in each state"); 
outcome.map.2016

correct.map.2016 <- plot_usmap(regions = "state", data = forecasts_2016, 
values = "statecorrect_o", labels = FALSE) + scale_fill_manual(name = "
                             ", values = c("#00b300", "#e5e5e5"), limits = c("Correct", "Incorrect")) +  
theme(plot.title = element_text(size = 10, face = "bold", hjust = 0.5)) + 
theme(legend.position = "bottom", legend.text = element_text(size = 8, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), 
"lines")) + theme(legend.key.size = unit(0.4, "cm")) + ggtitle("(c) Correct and incorrect forecasts"); 
correct.map.2016

layout_matrix <- matrix(c(1, 1, 2, 2, 4, 3, 3, 4), nrow = 2, byrow = TRUE)
map.2016 <- grid.arrange(forecast.map.2016, outcome.map.2016, correct.map.2016, 
layout_matrix = layout_matrix); map.2016

dev.copy(pdf, "map_2016.pdf")
dev.off()


################################################################################
## 2020 ELECTION

trump.2020 <- statebins(forecasts_2020, value_col = "trump_v_2020", name = "                   
                        Vote share  ", palette = "Reds", 
direction = 1) + theme_statebins() + theme(legend.position = "bottom") + 
theme(plot.margin = unit(c(0,0,0,0), "lines")) + ggtitle("(a) Donald Trump predicted vote share") +
theme(plot.title = element_text(size = 11, face = "bold", hjust = 0.5)); 
trump.2020

biden.2020 <- statebins(forecasts_2020, value_col = "biden_v_2020", name = "                   
                        Vote share  ", palette = "Blues", 
direction = 1) + theme_statebins() + theme(legend.position = "bottom") + 
theme(plot.margin = unit(c(0,0,0,0), "lines")) + ggtitle("(b) Joe Biden predicted vote share") + 
theme(plot.title = element_text(size = 11, face = "bold", hjust = 0.5)); 
biden.2020

forecast.winner.2020 <- mutate(forecasts_2020, value = fstatewinner_2020) %>% 
statebins(font_size = 3, dark_label = "white", light_label = "white",
ggplot2_scale_function = scale_fill_manual, name = "                  ",
values = c("Joe Biden" = "#2166ac", "Donald Trump" = "#b2182b")) + theme_statebins() + 
theme(legend.position = "bottom", legend.text = element_text(size = 11, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), "lines")) + 
ggtitle("(c) 2020 predicted winner in each state") + theme(plot.title = element_text(size = 11, 
face = "bold", hjust = 0.5)) + theme(legend.key.size = unit(0.8, "cm")); forecast.winner.2020

winner.2016 <- mutate(forecasts_2016, value = fstatewinner_o) %>% statebins(font_size = 3,
dark_label = "white", light_label = "white", ggplot2_scale_function = scale_fill_manual, name = "             ", 
values = c("Hillary Clinton" = "#2166ac", "Donald Trump" = "#b2182b")) + theme_statebins() + 
theme(legend.position = "bottom", legend.text = element_text(size = 11, 
margin = margin(r = 10, unit = "pt"))) + theme(plot.margin = unit(c(0,0,0,0), "lines")) + 
ggtitle("(d) 2016 actual winner in each state") + theme(plot.title = element_text(size = 11,
face = "bold", hjust = 0.5)) + theme(legend.key.size = unit(0.8, "cm")); winner.2016

map.2020 <- ggarrange(trump.2020, biden.2020, NULL, NULL, forecast.winner.2020, winner.2016, 
ncol = 2, nrow = 3, heights = c(1, 0.2, 1, 1, 0.2, 1)); map.2020

dev.copy(pdf, "map_2020.pdf")
dev.off()